const path = require('path');

// 代理方式：
module.exports = {
  publicPath: '/Music_H5',
  configureWebpack: {
    resolve: {
      alias: {
        'components': '@/components',
        'request': '@/request',
        'views': '@/views',
        'assets': '@/assets',
        'common': '@/common',
      }
    }
  },
  devServer: {
    open: true, //是否自动弹出浏览器页面
    host: "localhost",
    port: '80',
    https: false, //是否使用https协议
    hotOnly: true, //是否开启热更新
    proxy: {
      '/api': {
        target: 'http://localhost:3000/', //API服务器的地址
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        },
        // 突破host和origin的限制
        headers: {
          referer: 'http://localhost:3000/',
          origin: 'http://localhost:3000/',
          host: 'http://localhost:3000/'
        }
      },
    },
  },
  chainWebpack: config => {
    const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
    types.forEach(type => addStyleResource(config.module.rule('less').oneOf(type)))
    // 删除预加载的路由
    config.plugins.delete('prefetch')
  },
  // eslint:
  lintOnSave: false,

}

function addStyleResource(rule) {
  rule.use('style-resource')
    .loader('style-resources-loader')
    .options({
      patterns: [
        // 在此处添加less的mixin和变量
        path.resolve(__dirname, './src/assets/less/less_mixin.less'),
        path.resolve(__dirname, './src/assets/less/config.less')
      ],
    })
}
